home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS24.ADF / BNTools / Why.ASM < prev    next >
Assembly Source File  |  1988-04-16  |  7KB  |  234 lines

  1. ; Tabs set every 8.
  2. ;
  3. ;BETTERCLI(tm) "WHY" Command, release 1
  4. ;
  5. ;BETTERCLI WHY (C)1987 Bryce Nesbitt.  Unlimited free non-exclusive licence
  6. ;hereby    granted    to any sentient    being to use or    abuse this code    in any way
  7. ;whatsoever provided that this and any other copyright notices remain fully
  8. ;attached and are reproduced in    any simultaneously distributed printed matter
  9. ;and with the exception    that, without prior written permission,    it not
  10. ;be utilized by    any entity that    has been commonly referred to as Robert
  11. ;W. Skyles, Skyles Electric Works, Jim Drew, Regie Warren or any organization
  12. ;founded by, controlled, employing or profiting    any such entity, it's
  13. ;offspring or spouses.    ARP and    FISH use welcome.
  14. ;Author    correspondence,    bug or stupidity reports may be    directed to:
  15. ;    Bryce Nesbitt
  16. ;    1712 Marin Ave.
  17. ;    Berkeley, Ca 94707-2206
  18. ;
  19. ;This program replaces the CLI WHY command, providing faster execution and
  20. ;enhanced functionality.  The old WHY command was simply a stub    that called
  21. ;'C:FAULT', and thus could not be made properly RESIDENT.  This command was
  22. ;to replace FAULT as well, however the BCPL code does something    funky
  23. ;when calling FAULT, and I could not discover it's secret.
  24. ;
  25. ; Return code convention:
  26. ;  20  FAIL  -serious error, DOS will not open,    out of memory.
  27. ;  10  ERROR -user caused error    (syntax, file not found    etc.)
  28. ;         -less serious than    FAIL.
  29. ;  5   WARN  -technicality (file not found on DELETE, for example)
  30. ;  0   OK    -command sucessful, operation completed.
  31. ;
  32. ;This code is REUSABLE,REENTRANT and fully RESIDENT COMPATIBLE.
  33. ;Stack 1600 ok.
  34. *************************
  35. jsrlib    macro
  36.     xref    _LVO\1
  37.     jsr    _LVO\1(a6)
  38.     endm
  39. jmplib    macro
  40.     xref    _LVO\1
  41.     jmp    _LVO\1(a6)
  42.     endm
  43.     ;INCLUDE 'lib/exec_lib.i'    ;You don't have these files
  44.     ;INCLUDE 'lib/dos_lib.i'    ;so please ignore these lines.
  45.     INCLUDE    'libraries/dosextens.i'
  46. *************************
  47.         CODE
  48. outhand        equr    d6
  49. failcode    equr    d5
  50. proc        equr    a5
  51. cli        equr    a4
  52. ;d0-d4 a0-a3 scratch
  53. ;-- Setup --
  54. StartUp:    moveq    #20,failcode    ;default-SEVERE    failure
  55.         move.l    4,a6        ;get exec library base pointer
  56.         lea    dosname(pc),a1
  57.         jsrlib    OldOpenLibrary    ;get this... Compatability with    V1.0!
  58.         move.l    d0,outhand    ;temp for DOSBase
  59.         beq.s    e_dos        ;fail if it will not open
  60.         suba.l    a1,a1        ;find THIS task
  61.         jsrlib    FindTask
  62.         move.l    d0,proc
  63.         move.l    pr_CLI(proc),cli
  64.         adda.l    cli,cli        ;ban the BPTR!!
  65.         adda.l    cli,cli        ;ban the BPTR!!
  66.         move.l    outhand,a6    ;DOSBase
  67.         jsrlib    Output
  68.         move.l    d0,outhand
  69.         beq.s    e_output
  70. ;--
  71.         lea    mes1s(pc),a0    ;'Fail code '
  72.         moveq    #mes1e-mes1s,d3
  73.         bsr.s    DOWRITED
  74. ;-- Get    fail code --
  75.         move.l    cli_ReturnCode(cli),d0
  76.         bsr.s    PRINTDECIMAL
  77. ;--
  78.         lea    mes2s(pc),a0    ;'and error code '
  79.         moveq    #mes2e-mes2s,d3
  80.         bsr.s    DOWRITED
  81. ;-- Print error    number --
  82.         move.l    cli_Result2(cli),d0
  83.         bsr.s    PRINTDECIMAL
  84. ;--
  85.         lea    mes3s(pc),a0    ;';'
  86.         moveq    #mes3e-mes3s,d3
  87.         bsr.s    DOWRITED
  88. ;-- Print error    text --
  89.         move.l    cli_Result2(cli),d0
  90.         bsr.s    PCODE
  91.         moveq    #0,failcode
  92. e_error
  93. e_output    move.l    a6,a1
  94.         move.l    4,a6
  95.         jsrlib    CloseLibrary
  96. e_dos        move.l    failcode,d0
  97. rts1        rts
  98. ;
  99. ;DOWRITED(pointer,length)
  100. ;      a0      d3
  101. ;Aborts    if error
  102. ;
  103. DOWRITED    ;[d3=length]
  104.         move.l    a0,d2
  105.         move.l    outhand,d1
  106.         jsrlib    Write
  107.         cmp.l    d0,d3
  108.         beq.s    rts1
  109. e_badwrite    addq.l    #4,a7    ;pop return off    stack
  110.         jsrlib    IoErr
  111.         move.l    d0,pr_Result2(proc)
  112.         bra.s    e_error    ;(return code is set to    FAIL, 20)
  113. ;
  114. ;
  115. ;
  116. PCODE        moveq    #10,d1
  117.         lea    table(pc),a1
  118. checknext    move.l    a1,a0        ;Save pointer to this line
  119.         moveq    #-1,d3
  120. findend        cmp.b    (a1)+,d1    ;count length
  121.         dbeq    d3,findend    ;68010 loop mode!
  122.         neg.l    d3        ;compensate for    backwards count
  123.         subq.l    #1,d3        ;tweak
  124.         cmp.b    #$ff,(a0)
  125.         beq.s    gotit        ;end of    list, use default
  126.         cmp.b    (a0),d0
  127.         bne.s    checknext
  128. gotit        addq.l    #1,a0        ;skip error #
  129.         bra.s    DOWRITED    ;[a0-string|d3-len]
  130. ;
  131. ;Bloated, slow, kludg-o 32 bit signed print decimal routine.
  132. ;destroys D2,D3
  133. ;
  134. countvar    equr    d1
  135. tableoffset    equr    d2
  136.  
  137. PRINTDECIMAL    moveq    #-4,tableoffset
  138.         subq.l    #6,a7
  139.         subq.l    #6,a7    ;reserve 12 bytes for number
  140.         move.l    a7,a0
  141.         tst.l    d0
  142.         beq.s    zero
  143.         bpl.s    positive
  144.         move.b    #'-',(a0)+
  145.         neg.l    d0
  146. positive    addq.l    #4,tableoffset
  147.         cmp.l    table2(pc,tableoffset.l),d0
  148.         bcs.s    positive    ;BLO
  149.  
  150. doloop        move.l    table2(pc,tableoffset.w),countvar
  151.         beq.s    endofnum
  152.         moveq    #-1,countvar
  153. subloop        addq.l    #1,countvar
  154.         sub.l    table2(pc,tableoffset.w),d0
  155.         bcc.s    subloop
  156.         add.l    table2(pc,tableoffset.w),d0 ;Ooops! Too    far!!
  157.         ori.b    #$30,countvar
  158.         move.b    countvar,(a0)+
  159.         addq.l    #4,tableoffset
  160.         bra.s    doloop
  161.  
  162. zero        move.b    #$30,(a0)+
  163. endofnum    suba.l    a7,a0
  164.         move.l    a0,d3
  165.         move.l    a7,d2
  166.         move.l    outhand,d1
  167.         jsrlib    Write
  168.         addq.l    #6,a7
  169.         addq.l    #6,a7
  170.         cmp.l    d0,d3
  171.         bne.s    e_badwrite
  172.         rts
  173.  
  174. table2        dc.l    1000000000
  175.         dc.l    100000000
  176.         dc.l    10000000
  177.         dc.l    1000000
  178.         dc.l    100000
  179.         dc.l    10000
  180.         dc.l    1000
  181.         dc.l    100
  182.         dc.l    10
  183.         dc.l    1
  184.         dc.l    0
  185. dosname        dc.b 'dos.library',0
  186. mes1s        dc.b 'Fail code '
  187. mes1e
  188. mes2s        dc.b ', and error code '
  189. mes2e
  190. mes3s        dc.b '; '
  191. mes3e
  192.         dc.b '(C)1987 Bryce Nesbitt'
  193. ;
  194. ;Error message table. Feel free    to translate into other    languages such as
  195. ;German, Italian, or even English. Error numbers 200 and 201
  196. ;are unauthorized 'enhancments' to the standard.
  197. ;
  198. table    dc.b 103,'insufficient free store',10
  199.     dc.b 105,'task table full',10           ;!!Eliminate need!!
  200.     dc.b 120,'argument line invalid or too long',10
  201.     dc.b 121,'file is not an object module',10
  202.     dc.b 122,'invalid resident library during load',10
  203.        dc.b 200,'internal error',10
  204.        dc.b 201,'newer operating system required',10
  205.     dc.b 202,'object in use',10
  206.     dc.b 203,'object already exists',10
  207.     dc.b 204,'directory not found',10
  208.     dc.b 205,'object not found',10
  209.     dc.b 206,'invalid window description',10
  210.        ;dc.b 207,'object too large',10              ;obsolete
  211.     dc.b 209,'packet request type unknown',10
  212.     dc.b 210,'stream name component invalid',10 ;what??
  213.     dc.b 211,'invalid object lock',10
  214.     dc.b 212,'object not of required type',10
  215.     dc.b 213,'disk not validated',10
  216.     dc.b 214,'disk write-protected',10
  217.     dc.b 215,'rename across devices attempted',10
  218.     dc.b 216,'directory not empty',10
  219.        ;dc.b 217,'too many levels;,10               ;obsolete
  220.     dc.b 218,'device (or volume) not mounted',10
  221.     dc.b 219,'seek failure',10
  222.     dc.b 220,'comment too big',10
  223.     dc.b 221,'disk full',10
  224.     dc.b 222,'file is protected from deletion',10
  225.     dc.b 223,'file is write protected',10
  226.     dc.b 224,'file is read protected',10
  227.     dc.b 225,'not a valid DOS disk',10
  228.     dc.b 226,'no disk in drive',10
  229.     ;dc.b 227,'can',$27,'t open window',10
  230.     ;dc.b 228,'can',$27,'t open screen',10
  231.     dc.b 232,'no more entries in directory',10
  232.     dc.b 255,'no error message',10
  233. ;-- end --
  234.